package com.waitingresult.thread.queue;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * All right reserved,Designed By WangShuai
 *
 * @author : WangShuai
 * @version : V1.0
 * @ClassName : ArrayBlockingQueueDemo
 * @Description :
 * @date : 2022/9/22 14:22
 */
public class ArrayBlockingQueueDemo {
    public static void main(String[] args) throws Exception{

        ArrayBlockingQueue queue = new ArrayBlockingQueue(10);

        //生产者生产数据

        queue.add("第一个数据");
        new Thread(()->{
            while (true){
                try {
                    Thread.sleep(1000);
                    Object poll = queue.poll();
                    if(poll != null){
                        System.err.println(poll);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
        Thread.sleep(5000);
        queue.put("put第二个数据");


    }
}
